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K_UNKNOWN_KEY,
	K_UNKNOWN_KEY,
	K_UNKNOWN_KEY,
	K_UNKNOWN_KEY,
	K_WORLD_0,
	K_WORLD_1,
	K_WORLD_2,
	K_WORLD_3,
	K_WORLD_4,
	K_WORLD_5,
	K_WORLD_6,
	K_WORLD_7,
	K_WORLD_8,
	K_WORLD_9,
	K_WORLD_10,
	K_WORLD_11,
	K_WORLD_12,
	K_WORLD_13,
	K_WORLD_14,
	K_WORLD_15,
	K_WORLD_16,
	K_WORLD_17,
	K_WORLD_18,
	K_WORLD_19,
	K_WORLD_20,
	K_WORLD_21,
	K_WORLD_22,
	K_WORLD_23,
	K_WORLD_24,
	K_WORLD_25,
	K_WORLD_26,
	K_WORLD_27,
	K_WORLD_28,
	K_WORLD_29,
	K_WORLD_30,
	K_WORLD_31,
	K_WORLD_32,
	K_WORLD_33,
	K_WORLD_34,
	K_WORLD_35,
	K_WORLD_36,
	K_WORLD_37,
	K_WORLD_38,
	K_WORLD_39,
	K_WORLD_40,
	K_WORLD_41,
	K_WORLD_42,
	K_WORLD_43,
	K_WORLD_44,
	K_WORLD_45,
	K_WORLD_46,
	K_WORLD_47,
	K_WORLD_48,
	K_WORLD_49,
	K_WORLD_50,
	K_WORLD_51,
	K_WORLD_52,
	K_WORLD_53,
	K_WORLD_54,
	K_WORLD_55,
	K_WORLD_56,
	K_WORLD_57,
	K_WORLD_58,
	K_WORLD_59,
	K_WORLD_60,
	K_WORLD_61,
	K_WORLD_62,
	K_WORLD_63,
	K_WORLD_64,
	K_WORLD_65,
	K_WORLD_66,
	K_WORLD_67,
	K_WORLD_68,
	K_WORLD_69,
	K_WORLD_70,
	K_WORLD_71,
	K_WORLD_72,
	K_WORLD_73,
	K_WORLD_74,
	K_WORLD_75,
	K_WORLD_76,
	K_WORLD_77,
	K_WORLD_78,
	K_WORLD_79,
	K_WORLD_80,
	K_WORLD_81,
	K_WORLD_82,
	K_WORLD_83,
	K_WORLD_84,
	K_WORLD_85,
	K_WORLD_86,
	K_WORLD_87,
	K_WORLD_88,
	K_WORLD_89,
	K_WORLD_90,
	K_WORLD_91,
	K_WORLD_92,
	K_WORLD_93,
	K_WORLD_94,
	K_WORLD_95,
	K_KP_0,
	K_KP_1,
	K_KP_2,
	K_KP_3,
	K_KP_4,
	K_KP_5,
	K_KP_6,
	K_KP_7,
	K_KP_8,
	K_KP_9,
	K_KP_PERIOD,
	K_KP_SLASH,
	K_KP_STAR,
	K_KP_MINUS,
	K_KP_PLUS,
	K_KP_ENTER,
	K_KP_EQUALS,
	K_UP,
	K_DOWN,
	K_RIGHT,
	K_LEFT,
	K_INSERT,
	K_HOME,
	K_END,
	K_PAGE_UP,
	K_PAGE_DOWN,
	K_F1,
	K_F2,
	K_F3,
	K_F4,
	K_F5,
	K_F6,
	K_F7,
	K_F8,
	K_F9,
	K_F10,
	K_F11,
	K_F12,
	K_F13,
	K_F14,
	K_F15,
	K_UNKNOWN_KEY,
	K_UNKNOWN_KEY,
	K_UNKNOWN_KEY,
	K_NUMLOCK,
	K_CAPS_LOCK,
	K_SCROLL_LOCK,
	K_RIGHT_SHIFT,
	K_LEFT_SHIFT,
	K_RIGHT_CTRL,
	K_LEFT_CTRL,
	K_RIGHT_ALT,
	K_LEFT_ALT,
	K_RIGHT_META,
	K_LEFT_META,
	K_LEFT_SUPER,
	K_RIGHT_SUPER,
	K_ALT_GR,
	K_COMPOSE,
	K_HELP,
	K_PRINT_SCREEN,
	K_SYS_REQ,
	K_BREAK,
	K_MENU,
	K_POWER,
	K_EURO,
	K_UNDO
};

int process_input(void)
{
	SDL_Event e;
	KeyEvent k;

	while(SDL_PollEvent(&e))
	{
		switch(e.type)
		{
		
		case SDL_KEYDOWN:
		/*	k.event_type = k_chardown;
			k.key.c = (char)e.key.keysym.unicode;
			keyboard_event(k);*/
			k.event_type = K_KEYDOWN;
			k.key.k = sdl_keymap[e.key.keysym.sym];
			keyboard_event(k);
			break;
		case SDL_KEYUP:
			k.event_type = K_KEYUP;
			k.key.k = sdl_keymap[e.key.keysym.sym];
			keyboard_event(k);
			break;
		
		case SDL_QUIT:
			return 0;
		}

	}
	return 1;
	
}